#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btn_getstring_clicked()
{
    QString diologTitle = "测试输入";
    QString dialogLable = "请输入字符串";
    QLineEdit::EchoMode dialogInputMode = QLineEdit::PasswordEchoOnEdit;
    QString dialogInputDefaultText = "请在此输入文本";
    bool ok = false;

    QString inputText = QInputDialog::getText(this,diologTitle,dialogLable,dialogInputMode
                                              ,dialogInputDefaultText,&ok);
    if(ok && !inputText.isEmpty())
    {
        // ui->textEdit->setText(inputText);
        ui->textEdit->append(inputText);
    }
}


void Widget::on_btn_setFontSize_clicked()
{
    QString diologTitle = "测试修改字体大小";
    QString dialogLable = "设置字体大小";
    int oldFontSize = ui->textEdit->font().pointSize();
    bool ok;

    int newFontSize = QInputDialog::getInt(this,diologTitle,dialogLable,oldFontSize,0,60,1,&ok);

    if(ok)
    {
        QFont font = ui->textEdit->font();
        font.setPointSize(newFontSize);
        ui->textEdit->setFont(font);
    }
}


void Widget::on_btn_getDouble_clicked()
{
    QString diologTitle = "测试输入浮点数";
    QString dialogLable = "请输入浮点数";
    bool ok = false;

    double inputDouble = QInputDialog::getDouble(this,diologTitle,dialogLable,3.14,-1238679,23186,3,&ok);

    if(ok)
    {
        QString str =  QString::asprintf("用户输入了一个浮点数: %.2f",inputDouble);
        ui->textEdit->append(str);
    }

}


void Widget::on_btn_getItem_clicked()
{
    QString diologTitle = "测试下拉列表";
    QString dialogLable = "请选择级别";
    QStringList dialogList = {"优秀","良好"};
    dialogList << "及格" << "不及格" << "差" << "极差";
    bool ok = false;

    QString inputstr = QInputDialog::getItem(this,diologTitle,dialogLable,dialogList,0,false,&ok);

    if(ok && !inputstr.isEmpty())
        ui->textEdit->append(inputstr);
}

